package com.t282.crm.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.t282.crm.entity.BasDict;
import com.t282.crm.result.Result;
import com.t282.crm.service.BasDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags="基础数据")
@RequestMapping(value="/admin/dict")
public class BascDictcontroller {


    @Autowired
    private BasDictService basDictService;

    @ApiOperation(value="查询客户等级")
    @GetMapping(value = "/dictPage/{pagea}/{limit}")
    public Result findpage(@PathVariable  int pagea,
                           @PathVariable int limit,
                           Integer dictId,
                           String dictValue){
        //pege当前页,limit显示的页数
        IPage<BasDict>pages=new Page<BasDict>(pagea,limit);
        //条件
        QueryWrapper<BasDict>wp=new QueryWrapper<BasDict>();
        if(dictId!=null){
            wp.eq("dictId",dictId);
        }
        if(dictId!=null){
            wp.eq("dictValue",dictValue);
        }
        IPage<BasDict> page = basDictService.page(pages,wp);
        return  Result.ok(page);

    }

    @ApiOperation(value="编辑服务类型")
    @PostMapping(value = "/dictUpdate/{dictId}/{dictValue}")
    public Result findUpdate(@PathVariable Long dictId,@PathVariable String dictValue){
        BasDict BasDict=new BasDict();
        BasDict.setDictId(dictId);
        BasDict.setDictValue(dictValue);
        basDictService.updateById(BasDict);

        return Result.ok();
    }


    @ApiOperation(value="删除客户等级")
    @DeleteMapping(value = "/dictDelect/{dictId}")
    public Result findUpdate(@PathVariable Long dictId){

        basDictService.removeById(dictId);
        return Result.ok();
    }


}
